package com.iipaas.twheel;

/**
 * Description: 指针跳动
 * <p>
 * ClassName: TickWorker
 * date: 2021/6/18 9:51 AM
 *
 * @author JohnnyChin
 * @version 1.0
 * @since JDK 1.8
 **/
public class TickWorker<T> implements Runnable {
    private final TimingWheel<T> wheel;

    public TickWorker(TimingWheel<T> wheel) {
        this.wheel = wheel;
    }

    @Override
    @SuppressWarnings("all")
    public void run() {
        while (wheel.isRunning()) {
            wheel.writeLock();
            try {
                wheel.tick();
            } finally {
                wheel.writeUnLock();
            }
            try {
                Thread.sleep(wheel.ticksPerWheel());
            } catch (InterruptedException e) {
                return;
            }
        }
    }
}
